home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Online / cnetdevice / src / include / debugs.i < prev    next >
Text File  |  2000-05-06  |  6KB  |  273 lines

  1. ;----------------------------------------------------------------------------
  2. ;                     Debug Info sent to serial port
  3. ;----------------------------------------------------------------------------
  4. ;                        by Bruce Abbott 11-4-97
  5. ;                     Fixed by Harry Sintonen 6-5-00
  6. ;
  7. ; NOTE: If you want to redirect the serial output, execute eg.
  8. ;
  9. ;       run >nil: sushi >"con:50/50/400/160/sushi /auto" NOPROMPT
  10. ;
  11. ;----------------------------------------------------------------------------
  12. ;
  13. ;   types supported  %ld =  32 bit signed decimal
  14. ;                    %lx =  32 bit hex
  15. ;                    %lc =  32 bit char (eg 'ILBM')
  16. ;                    %d  =  16 bit signed decimal
  17. ;                    %x  =  16 bit hex
  18. ;                    %c  =   8 bit character
  19. ;                    %s  =  string pointer (string ends with NULL)
  20. ;
  21. ;   modifiers        0   =  leading spaces for decimal, 0's for hex
  22. ;                  (1-9) =  max number of characters in number
  23. ;
  24. ;
  25. ;   parameters   anything that can be source for 'move.l' instruction
  26. ;
  27. ;   example  bug <"decimal=%03ld, hex=$%03lx">,#27,#$0000001B
  28. ;
  29. ;            prints:- 'decimal= 27, hex=$01b'
  30. ;
  31. ;
  32.  
  33. Bug MACRO   "text",parm1,parm2,parm3,parm4,parm5,parm6,parm7,parm8
  34.     IFD     debug
  35.     ifnc    "","\9"
  36.     move.l  \9,-(sp)
  37.     endc
  38.     ifnc    "","\8"
  39.     move.l  \8,-(sp)
  40.     endc
  41.     ifnc    "","\7"
  42.     move.l  \7,-(sp)
  43.     endc
  44.     ifnc    "","\6"
  45.     move.l  \6,-(sp)
  46.     endc
  47.     ifnc    "","\5"
  48.     move.l  \5,-(sp)
  49.     endc
  50.     ifnc    "","\4"
  51.     move.l  \4,-(sp)
  52.     endc
  53.     ifnc    "","\3"
  54.     move.l  \3,-(sp)
  55.     endc
  56.     ifnc    "","\2"
  57.     move.l  \2,-(sp)
  58.     endc
  59.  
  60.     ;bsr.w   bugprintf
  61.     ;add.w   #(narg-1)*4,sp
  62.     ;bra.s   .bugend\@
  63.     dc.w     $6100,bugprintf+8-.bugtext\@,$4FEF,(narg-1)*4
  64.     dc.b     $60,(.bugend\@-.bugtext\@)
  65.  
  66. .bugtext\@:
  67.     dc.b    \1,0
  68.     even
  69. .bugend\@:
  70.     ENDC
  71.     ENDM
  72.  
  73.  
  74.  IFD debug
  75.  
  76.  IFND _LVORawPutChar
  77. _LVORawPutChar = -516
  78.  ENDC
  79.  
  80.  
  81. ; do NOT include debugs.i before your startup code!
  82.  
  83. wrongplace:
  84.   moveq   #-1,d0
  85.   rts                   ; abort if start of program!
  86.  
  87.  
  88. bugprintf:
  89.   movem.l d0-d7/a0-a6,-(sp)
  90.   move.l  60(sp),a2     ; point to string (after bsr bugprintf)
  91.   addq.w  #6,a2
  92.   lea     64(sp),a3     ; point to parameters on stack
  93.   move.l  4.w,a6
  94. .rawloop:
  95.   move.b  (a2)+,d0      ; get next char in formatting string
  96.   beq     .done
  97.   moveq   #0,d4
  98.   cmp.b   #'%',d0       ; type id ?
  99.   bne     .print
  100. .gettype:
  101.   move.b  (a2)+,d0
  102.   beq     .done
  103.   cmp.b   #'0',d0
  104.   beq.s   .lead0
  105.   cmp.b   #'9',d0
  106.   bhi.s   .type
  107.   sub.b   #'0',d0
  108.   move.b  d0,d4
  109.   bra.s   .gettype
  110. .lead0:
  111.   bset    #31,d4        ; flag LEADING ZEROS
  112.   bra.s   .gettype
  113. .type:
  114.   cmp.b   #'s',d0       ; string ?
  115.   beq     .dostring
  116.   move.b  d0,d5         ; d5 = last char
  117.   cmp.b   #'l',d0
  118.   bne.s   .dotype
  119.   bset    #30,d4        ; flag LONG SIZE
  120. .donum:
  121.   move.b  (a2)+,d0      ; get type after 'l'
  122.   beq     .done
  123. .dotype:
  124.   cmp.b   #'x',d0       ; hex ?
  125.   beq     .hex
  126.   cmp.b   #'d',d0       ; decimal ?
  127.   beq.s   .dec
  128.   cmp.b   #'c',d0
  129.   beq.s   .char
  130.   bra     .print        ; unsupported type so just print it
  131. .char:
  132.   move.l  (a3)+,d0
  133.   cmp.b   #'l',d5
  134.   bne     .print        ; longword char ?
  135.   subq.w  #1,d4
  136.   bmi.s   .nolen
  137.   move.w  d4,d2
  138.   bra.s   .charloop
  139. .nolen:
  140.   moveq   #3,d2         ; default 4 chars
  141. .charloop:
  142.   rol.l   #8,d0
  143.   jsr     _LVORawPutChar(a6)
  144.   dbf     d2,.charloop
  145.   bra     .rawloop
  146. .dec:
  147.   tst.w   d4
  148.   bne.s   .declen
  149.   move.w  #10,d4        ; default 10 digits
  150. .declen:
  151.   move.l  (a3)+,d3      ; get number
  152.   btst    #30,d4
  153.   bne.s   .declong
  154.   ext.l   d3
  155. .declong:
  156.   tst.l   d3
  157.   bmi.s   .negative
  158.   neg.l   d3
  159.   bra.s   .firstdig
  160. .negative
  161.   moveq   #'-',d0
  162.   jsr     _LVORawPutChar(a6)
  163. .firstdig:
  164.   lea     .dectab(pc),a4
  165.   moveq   #9,d5
  166. .getdiv:
  167.   move.l  (a4)+,d2      ; get divisor
  168.   beq.s   .lastdig
  169.   moveq   #-1,d0
  170. .div10:
  171.   add.l   d2,d3
  172.   dbgt    d0,.div10
  173.   sub.l   d2,d3
  174.   addq.w  #1,d0         ; d0 = -digit
  175.   neg.b   d0
  176.   add.b   #'0',d0       ; d0 = char
  177.   cmp.w   d4,d5
  178.   bhi.s   .skipdec
  179.   btst    #29,d4        ; printed a digit yet ?
  180.   bne.s   .printd
  181.   cmp.b   #'0',d0
  182.   bne.s   .printdec
  183.   btst    #31,d4        ; leading spaces ?
  184.   beq.s   .skipdec
  185.   moveq   #' ',d0       ; lead space
  186.   bra.s   .printd
  187. .printdec:
  188.   bset    #29,d4
  189. .printd:
  190.   jsr     _LVORawPutChar(a6)
  191. .skipdec:
  192.   subq.w  #1,d5
  193.   bra.s   .getdiv
  194. .lastdig:
  195.   neg.b   d3
  196. .zero:
  197.   add.b   #'0',d3
  198.   move.b  d3,d0
  199.   bra.s   .print
  200. .hex:
  201.   btst    #30,d4
  202.   bne.s   .hexlong
  203.   tst.w   d4
  204.   bhi.s   .hexword
  205.   move.w  #4,d4          ; default 4 digits in hex word
  206. .hexword:
  207.   moveq   #3,d2
  208.   move.l  (a3)+,d5
  209.   swap    d5
  210.   bra.s   .hexloop
  211. .hexlong
  212.   tst.w   d4
  213.   bhi.s   .gethexlong
  214.   move.w  #8,d4         ; default 8 digits in hex longword
  215. .gethexlong:
  216.   moveq   #7,d2
  217.   move.l  (a3)+,d5
  218. .hexloop:
  219.   rol.l   #4,d5
  220.   move.w  d5,d0
  221.   and.w   #$000f,d0
  222.   move.b  .hextab(pc,d0.w),d0
  223.   cmp.w   d4,d2
  224.   bhs.s   .skiphex
  225.   cmp.b   #'0',d0       ; '0' ?
  226.   bne.s   .printhex
  227.   btst    #31,d4        ; leading 0's wanted ?
  228.   beq.s   .skiphex
  229. .printhex:
  230.   bset    #31,d4
  231.   jsr     _LVORawPutChar(a6)
  232. .skiphex:
  233.   dbf     d2,.hexloop
  234.   bra     .rawloop
  235. .dostring:
  236.   move.l  (a3)+,d5
  237.   beq.s   .strdone
  238.   exg     d5,a2
  239. .strloop:
  240.   move.b  (a2)+,d0
  241.   beq.s   .strdone
  242.   jsr     _LVORawPutChar(a6)
  243.   bra.s   .strloop
  244. .strdone:
  245.   exg     d5,a2
  246.   bra     .rawloop
  247. .print:
  248.   jsr     _LVORawPutChar(a6)
  249.   bra     .rawloop
  250. .done:
  251.   movem.l (sp)+,d0-d7/a0-a6
  252.   rts
  253.  
  254.  
  255. .hextab:
  256.   dc.b   "0123456789abcdef"
  257.  
  258. .dectab:
  259.   dc.l 100000000
  260.   dc.l 10000000
  261.   dc.l 1000000
  262.   dc.l 100000
  263.   dc.l 10000
  264.   dc.l 1000
  265.   dc.l 100
  266.   dc.l 10
  267.   dc.l 0
  268.  
  269.   cnop 0,4
  270.  
  271.  ENDC
  272.  
  273.